'use strict';
import { get } from 'utils/request.js';

export function callPay(payObj) { ;
  // data为获取paySign时需要传的参数
  var data = {};
  get({'path': payObj.url}, {id: payObj.id}).then(function(res){
    var ratingData = res.data;
    if (ratingData.ret == 0) {
      var resData = ratingData.data;
      wx.requestPayment({
        'timeStamp': resData.timeStamp,
        'nonceStr': resData.nonceStr,
        'package': resData.package,
        'signType': 'MD5',
        'paySign': resData.paySign,
        'success': function(res) {
          payObj.success(res)
        },
        'fail': function(res) {
          payObj.fail(res)
        }
      });
    }else{
      wx.showToast({
        title: res.data.msg,
        image: '/images/com/error.svg',
        duration: 2000
      })
      return false;
    }
  }, function(res){
    wx.showToast({
      title: res.data.msg,
      image: '/images/com/error.svg',
      duration: 2000
    })
    return false;
  })
}
